package com.newbie.pet.controller;

import com.newbie.pet.model.CustomerEntity;
import com.newbie.pet.service.impl.CustomerService;
import com.newbie.pet.wrap.DPage;
import com.newbie.pet.wrap.P;
import com.newbie.pet.wrap.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 类描述：顾客信息接口
 *
 * @author zhangkailiang
 * @date 2020/5/16
 */
@Api(tags = "顾客信息接口")
@RestController
@RequestMapping("/api/customer")
public class CustomerController {
    @Autowired
    private CustomerService customerService;

    @ApiOperation(value = "保存顾客信息", notes = "保存顾客信息")
    @PostMapping("/save")
    public R<Boolean> save(@RequestBody CustomerEntity customerEntity) {
        return R.ok(customerService.save(customerEntity) > 0);
    }

    @ApiOperation(value = "修改顾客信息", notes = "修改顾客信息")
    @PostMapping("/update")
    public R<Boolean> update(@Validated @RequestBody CustomerEntity customerEntity) {
        return R.ok(customerService.updateById(customerEntity));
    }

    @ApiOperation(value = "删除顾客信息", notes = "删除顾客信息")
    @PostMapping("/delete")
    public R<Boolean> delete(@RequestBody Long id) {
        return R.ok(customerService.deleteById(id));
    }

    @ApiOperation(value = "分页查询顾客信息", notes = "分页查询顾客信息")
    @PostMapping("/find/page")
    public R<DPage<CustomerEntity>> findPage(@RequestBody P<CustomerEntity> customerEntity) {
        return R.ok(customerService.findPageByCustomer(customerEntity));
    }

    @ApiOperation(value = "查询顾客信息", notes = "查询顾客信息")
    @PostMapping("/find/one")
    public R<CustomerEntity> findOneById(@RequestBody Long id) {
        return R.ok(customerService.findOneById(id));
    }
}
